package net.tomblog.app.swingheil.activity;

import net.tomblog.app.swingheil.R;
import net.tomblog.app.swingheil.parser.ArticleParser;
import net.tomblog.app.swingheil.util.L;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * Swing Heil 시작 Activity
 * 
 * @author hyunung.park (parkbear01@gmail.com)
 * 
 */
public class SwingHeilActivity extends BaseActivity {
	
	private static final String TAG = "SwingHeilActivity";
	
	private Button mNaverBoardButton;
	private Button mDaumBoardButton;
	private Button mSwingHeilBoardButton;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
    	L.d(TAG, " >>> called onCreate()");
        setContentView(R.layout.swing_heil_activity);
        
        // http.keepAlive를 false로 설정하지 않으면 http request를 보낼때, 두번에 한번 에러가 난다.
        System.setProperty("http.keepAlive", "false");
        
        // Inflate views.
        inflateView();
    
        // Initialize objects.
        initObject();
        
        super.onCreate(savedInstanceState);  
    }
	
	@Override
	protected void onStop() {
		L.d(TAG, " >>> called onStart()");
		super.onStop();
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.swing_heil_menu, menu);
		
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent intent;
		switch (item.getItemId()) {
		case R.id.set_oauth:
			intent = new Intent(SwingHeilActivity.this, SetUpOAuthActivity.class);
			startActivity(intent);
			return true;
		default:
			break;
		}

		return false;
	}

	private void inflateView() {
		L.d(TAG, " >>> called inflateView()");
		
		mRootView  = (ViewGroup)findViewById(R.id.root);
		mNaverBoardButton = (Button)findViewById(R.id.naver_board_button);
		mDaumBoardButton = (Button)findViewById(R.id.daum_board_button);
		mSwingHeilBoardButton = (Button)findViewById(R.id.swingheil_board_button);

	}
	
    private void initObject() {
    	L.d(TAG, " >>> called initObject()");
    	
    	mNaverBoardButton.setOnClickListener(new OnClickListener() {
    		@Override
    		public void onClick(View v) {
    			String cafeId = ArticleParser.getCafeId(ArticleParser.CAFE_SWING_ADE);
    			String boardId = ArticleParser.getNoticeBoardId(ArticleParser.CAFE_SWING_ADE);
    			Intent intent = new Intent(SwingHeilActivity.this, ArticleListActivity.class);
    			intent.putExtra(ArticleParser.INTENT_CAFE_ID, cafeId);
    			intent.putExtra(ArticleParser.INTENT_BOARD_ID, boardId);
    			startActivity(intent);
    		}
    	});
    	mDaumBoardButton.setOnClickListener(new OnClickListener() {
    		@Override
    		public void onClick(View v) {
    			String cafeId = ArticleParser.getCafeId(ArticleParser.CAFE_CRAZY_SWING);
    			String boardId = ArticleParser.getNoticeBoardId(ArticleParser.CAFE_CRAZY_SWING);
    			Intent intent = new Intent(SwingHeilActivity.this, ArticleListActivity.class);
    			intent.putExtra(ArticleParser.INTENT_CAFE_ID, cafeId);
    			intent.putExtra(ArticleParser.INTENT_BOARD_ID, boardId);
    			startActivity(intent);
    		}
    	});
    	mSwingHeilBoardButton.setOnClickListener(new OnClickListener() {
    		@Override
    		public void onClick(View v) {
    			String cafeId = ArticleParser.getCafeId(ArticleParser.CAFE_SWING_HEIL);
    			String boardId = ArticleParser.getNoticeBoardId(ArticleParser.CAFE_SWING_HEIL);
    			Intent intent = new Intent(SwingHeilActivity.this, ArticleListActivity.class);
    			intent.putExtra(ArticleParser.INTENT_CAFE_ID, cafeId);
    			intent.putExtra(ArticleParser.INTENT_BOARD_ID, boardId);
    			startActivity(intent);
    		}
    	});
	}
}